// pages/My/Account/record.js
const Controllers = require('../../controllers/Controller.js').controller;
const agentStaffList = require('../../controllers/ControllerMy.js').controller.agentStaffList;
const app = getApp();
var now = new Date();
const Y = now.getFullYear();
const M = now.getMonth() + 1 > 9 ? now.getMonth() + 1 : '0' + now.getMonth() + 1;
Page({

  /**
   * 页面的初始数据
   */

  data: {
    page: {
      pageNumber: 1,
      pageSize: 10
    },
    list: [],
    totalRow: 0,
    isLoading: false,
    lastPage: true,
    endDate: Y + '-' + M
  },
  agentStaffList() {
    var that = this;
    var agentStaffId = that.data.agentStaffId;
    agentStaffList({agentStaffId}).then(res => {
      console.log('agentStaffList--res==', res);
      const { code, data, desc } = res;
      that.setData({
        list: data || []
      })
    })
  },
  bindDateChange(e) {
    var that = this;
    console.log('bindDateChange--e==', e);
    that.setData({
      time: e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    const { id, rent, cloud, time } = options;
    that.setData({
      agentStaffId: id,
      rent: parseFloat(rent).toFixed(2),
      cloud: parseFloat(cloud).toFixed(2),
      total: parseFloat(parseFloat(rent) + parseFloat(cloud)).toFixed(2),
      time
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    that.agentStaffList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if (that.data.isLoading || that.data.lastPage) {
      return;
    }
    that.data.page.pageNumber += 1;
    that.agentPage();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})